<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<%  
  response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin server
  response.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
  response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
  response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility
  String baseURL = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>抓取任务监控——恒拓运价魔方</title>
<link href="<%=request.getContextPath()%>/fare/css/base.css" rel="stylesheet" type="text/css" />

<link href="<%=request.getContextPath()%>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/fare/js/show.js" type="text/javascript" ></script>
<script src="<%=request.getContextPath()%>/fare/js/jquery/jquery-1.3.2.min.js" type="text/javascript" ></script>
<script src="<%=request.getContextPath()%>/fare/js/datePicker/WdatePicker.js" type="text/javascript" ></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/lib/json2.js" type="text/javascript"></script>

<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/show.js"></script>

<script type="text/javascript" src="<%=request.getContextPath()%>/fare/js/datePicker/WdatePicker.js"></script>

<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />


<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />


<script type="text/javascript">

function showm(sid){
var which = document.getElementById("lite" + sid);
var imgmenu = document.getElementById("ling" + sid);
	if (which.style.display == "none"){
		document.getElementById("lite" + sid).style.display="";
	}
	else{
		document.getElementById("lite" + sid).style.display="none";
		}

}
</script>

<script type="text/javascript">
	$(document).ready(function(){
		$('#fromCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
		$('#toCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	});
	$(document).ready(function(){
		$('#fromCity2').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
		$('#toCity2').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
		
		
		if($('#startTime').val()=="" && $('#endTime').val()==""){
			var nowDate = new Date();
			var nowMonthStr = Number(nowDate.getMonth()+1)+"";
			var nowDayStr = nowDate.getDate()+"";
			var dateStr="";
			
			if(nowMonthStr.length==1){
				nowMonthStr="-0"+nowMonthStr;
			}
			if(nowDayStr.length==1){
				nowDayStr="0"+nowDayStr;
			}
			dateStr= nowDate.getFullYear()+nowMonthStr+"-"+nowDayStr;
			
			
			$('#startTime').val(dateStr);
			$('#endTime').val(dateStr);
		}
	});
	
	
</script>

</head>

<body>

<form id="taskRecordForm" action="taskRecordAction!toQueryTaskRecordJsp.action" method="post">
<TABLE cellSpacing=1 cellPadding=3 width="100%" border=0 class="tabg">
  <TBODY>
  <TR class="tr1">
    <TD colspan="4" style="color:white">查询条件</TD>
  </TR>
  <TR class="tab">
<TD width="10%" style="text-align:left" height="26" class="td1">说&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;明：</TD>
    <TD  colspan="3">
    	<textarea readonly="readonly" rows="3" cols="50" style="text-align:left;resize: none; width: 500px; height: 54px; min-width: 500x; min-height: 54px; max-width: 500px; max-height: 54px;">
1)监控抓取引擎的任务执行情况，方便系统管理员在异常的情况下进行检查、调整频率、控制带宽等;
2)抓取时间段为必填项,可选择范围为10天的时间段;
    	</textarea>
  </TR>

  <TR class="tab">
    <TD height="26" width="10%" style="text-align:left" class="td1" align="center">
    		航&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;段：
    </TD>
    <TD width="40%" >
		<div style='margin: 10px auto;'>
			<span>从 </span> 
			<input id='fromCity' name="fromCity" type='text' value='' style="width: 100px" /> 
			<span>到</span> 
			<input id='toCity' name="toCity" type='text' value='' style="width: 100px" />
			<%-- <span style="color: #ff0000">*</span> --%><br />
			<br />
		</div>
	</TD>
	
    <TD height="26" width="10%" style="text-align:left" class="td1">网站名称：</TD>
    
    <TD colspan="3">
		<select class="easyui-combobox" name="grabChannelID" style="width: 150px;" id="grabChannelID">
			<option value="" selected="selected">全部</option>
			<c:choose>
				<c:when test="${sourceList == null}">
					</c:when>
					<c:otherwise>
						<c:forEach var="item" items="${sourceList }">
							<c:if test="${item.crawlStatus==1 }">
								<option value="${item.id}">${item.name}</option>
							</c:if>
						</c:forEach>
					</c:otherwise>
			</c:choose>
		</select>
	</TD>
  </TR>

  <TR class="tab">
  
    <TD  height="26" style="text-align:left" class="td1">
    	抓取时间段：
    </TD>
    
    <TD>
	    <span>从 </span>
	      <input id="startTime" name="startTime" type="text" id="text2" 
	        style="width: 100px;"  onClick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d'})" readonly="readonly">
	    <span>到</span>
      	<input id="endTime" name="endTime" type="text" id="text2" 
      	   style="width: 100px;"  onClick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d'})" readonly="readonly">
     <font color="red"> *</font>
    </TD>
    
    <TD  height="26" style="text-align:left" class="td1">下载状态：</TD>
    
    <TD>
    	<select id="status" name="status" style="width: 150px;">
    		<option value="">全部</option>
    		<option value="3">成功</option>
    		<option value="0">等待中</option>
    		<option value="1">启动中</option>
    		<option value="2">执行中</option>
    		<option value="-2">抓取失败</option><!-- 小于0的都为失败 -->
    		<option value="-3">解析失败</option>
    		<option value="-4">其他失败</option>
    	</select>
    </TD>
    
  </TR>
  
  <TR class="tab">
    <TD height="26" colspan="4" align="center">
    	<input name="Submit3" value="查询" id="monitorSubmit" style="width:80px;cursor: pointer;" type="button"/>
    </TD>
  </TR>
  
</TBODY>
</TABLE>
</form>
<p></p>
<div id="maingrid" style="margin-top:20px;"></div>
</body>
<script type="text/javascript">
var isenableData = [{ status:"-2", text: '抓取失败' }, 
                    { status:"-3", text: '解析失败'},
                    { status:"-4", text: '其他失败'},
					{ status:"0", text: '等待中'},
					{ status:"1", text: '启动中'},
					{ status:"2", text: '执行中'},
					{ status:"3", text: '成功'}];
var columns=[ 
			{ display: "序号",width : 30, render: function(data, index) { return (this.options.page-1)*this.options.pageSize+index+1; } },
			{display : '航班日期      ▽',width : 80,name : 'grabDate'}, 
			{display : '航段      ▽',	width : 180,name : 'leg'}, 
			{display : '执行耗时',width : 50,name : 'wasteTime'},
			{display : '网站名称      ▽',width : 100,name : 'grabChannel'}, 
			{display : '下载状态      ▽',width : 80 ,name : 'status',data: isenableData,
				render: function (item)
	            {
	                if (parseInt(item.status) == -2) 
	                	return '抓取失败';
	                else if(parseInt(item.status)==-3)
	                	return '解析失败';
	                else if(parseInt(item.status)==-4)
	                	return '其他失败';
	                else if(parseInt(item.status)==0)
	                	return '等待中';
	                else if(parseInt(item.status)==1)
	                	return '启动中';
	                else if(parseInt(item.status)==2)
	                	return '执行中';
	                else if(parseInt(item.status)==3)
	                	return '成功';
	            }
			}, 
			{display : '任务创建时间      ▽',width : 130,align:'center',name : 'createTime'}, 
			{display : '执行时间      ▽',width : 130,align:'center',name : 'startTime'},
			{display : '网页大小',width : 80,align:'center',name : 'sourceDataSize'},
			{display : '执行日志',width : 350,align:'center',name : 'remarks'}];
			
	//查询任务
    $(function(){
    	
	   $("#monitorSubmit").click(
		 function (){
			 
			var fromCity=$("#fromCity").val();
			if(fromCity=='中文/拼音'){
				fromCity="";
			}
			
			var toCity=$("#toCity").val();
			if(toCity=='中文/拼音'){
				toCity="";
			}
			
			if(fromCity!=""){
				if(toCity==""){
					alert("请选择终点城市");
					return false;
				}
			}
			
			if(toCity!=""){
				if(fromCity==""){
					alert("请选择起始城市");
					return false;
				}
			}
			
			if(fromCity!=""&&toCity!=""){
				if(fromCity==toCity){
					alert("出发地与目的地不能相同");
					return false;
				}
			}
			
			var grabChannelID=$("#grabChannelID").val();
			//alert(grabChannelID);
			
			var startTime=$("#startTime").val();
			var endTime=$("#endTime").val();
			if(startTime=="" || endTime ==""){
				alert("请输入正确的抓取时间段");
				return false;
			}
			
			var start=new Date(startTime.replace("-", "/").replace("-", "/"));  
			var end=new Date(endTime.replace("-", "/").replace("-", "/"));  
			  if(end<start){  
				alert("结束时间不能小于开始时间");
			    return false;  
			  }  
             
			  var sd;
			  var ed;
			  sd = startTime.split("-");
			  ed = endTime.split("-");
			  //sd[0]+"-"+sd[1]+"-"+sd[2]
			  var sdStr = new Date(sd[0],sd[1],sd[2]);
			  var edStr = new Date(ed[0],ed[1],ed[2]);
			  
			  var iDays = parseInt(Math.abs(edStr - sdStr) / 1000 / 60 / 60 /24);//把相差的毫秒数转换为天数
			  if(iDays>10){
				  alert("抓取时间段的选择范围为10天");
				  return false;
			  }
			  
	    	var status=$("#status").val();
	    	//alert(status);
	    	
	        var url="<%=request.getContextPath() %>/taskRecordAction!toQueryTaskRecordJsp.action"
	        +"?fromCity="+encodeURI(encodeURI(fromCity))+"&&toCity="+encodeURI(encodeURI(toCity))+
	        "&&grabChannelID="+grabChannelID+"&&startTime="+startTime+"&&endTime="+
	        endTime+"&&status="+status+"&&rd="+Math.random();
	        var i=0;
	        //1.定义liger表格
	        var manager=$("#maingrid").ligerGrid({
	             columns:columns,
                 url:url,
 				 //  pageSize:10,
				 width: '100%',
	             height:'100%',
	             onBeforeShowData:function (data){
	            	 i++;
	            	 if(i==1){
	            		 if(data.Total==0){
		 						alert("对不起,没有相关数据！");
			 					return false;
		 				}
	            	 }
	 				//return true;
	 			}
	          });
	        
	        // 2.设置查询选项
	        manager.setOptions({
                  url:url, //指定url
                  newPage:1, //指向第1页
                 // pagesizeParmName:pagesize,
                  dataAction:"server",
                  dataType:"server"
             });
	        
	        
	        
	        manager.loadData();  //加载数据
	        //alert(manager.getData());
	        //提示 对不起，无相关数据
	        //可以使用  onBeforeShowData(data)
	        
	        
	        
			
			//====================================
			//这是控制翻页输入框的代码请忽略它，css暂时无法控制，只能js控制
			//控制宽度还有输入长度
	        var e=$(".pcontrol input")[0];
			$(e).css({
				"width":"50px"
			});
			$(e).attr("maxlength",6);
			
			var e_span=$("span.l-bar-text")[0];
			e_span.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+e_span.innerHTML;
			
	        //====================================
			
	        
		 });
	});
	
</script>
</html>

